﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdverseEventReportSystem.Utils {
    public static class LogHelper {
		#region 日志
		/// <summary>
		/// 写文件日志
		/// </summary>
		/// <param name="msg">消息</param>
		/// <param name="logType">日志类型 枚举</param>
		public static void WriteLog(string msg, LogType logType) {
			string LogPath = ConfigHelper.GetConfigString("LogPath");
			if (string.IsNullOrEmpty(LogPath) || LogPath == "/") {
				LogPath = WebUtils.RootPhysicalPath;
			}
			string phyPath = LogPath + logType.ToString() + @"\";
			if (!Directory.Exists(phyPath))
				Directory.CreateDirectory(phyPath);
			string t = System.DateTime.Now.ToString("yyyyMMddHH");
			string sPath = phyPath + "\\" + t;
			string filename = "error";
			if (!Directory.Exists(sPath)) {
				Directory.CreateDirectory(sPath);
			}
			using (StreamWriter SW = File.AppendText(sPath + "\\" + filename + ".txt")) {
				SW.WriteLine(System.DateTime.Now.ToString());
				SW.WriteLine(msg);
				SW.WriteLine("------------------------------------------------------------------");
				SW.Close();
			}

		}
		#endregion
	}
}
